package commonClasses;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;

public class CleanCode {


	public static void main(String args[]) throws IOException{
		PrintStream ps = new PrintStream("J:\\BC3_IMT_Training\\Sections.txt");
		FileReader f = new FileReader(
				"J:\\BC3_IMT_Training\\Journal name and lines.txt");

		BufferedReader fb = new BufferedReader(f);
		String name = fb.readLine();
		int count=0;
		while (name != null) {
			String []split = name.split("\t");
			ArrayList<String> al = list();
			
			ps.print(split[0]);
			ps.print("\tStart:"+0);
				for(int i=0;i<al.size();i++){
					FileReader fr=new FileReader("J:\\BC3_IMT_Training\\txt\\"+split[0]+".txt");
					BufferedReader fbr=new BufferedReader(fr);
					String str=fbr.readLine();
					count=0;
					int c=0;
					while(str!=null){
						count++;
					if(str.equals((al.get(i))) || str.indexOf(al.get(i))==2||str.indexOf(al.get(i))==3 ||str.equals((al.get(i)+" "))||str.equals(" "+al.get(i))){
						if(c!=count)
						ps.print("\t"+al.get(i)+":"+count);
						c=count;
						
					}
					
					str=fbr.readLine();
					}
					
				}
				ps.print("\tEnd:"+count);
			ps.println();


			name = fb.readLine();
			}
		
	}
	
	
	public static ArrayList<String> list() throws IOException{
		
		ArrayList<String> al = new ArrayList<String>();
		FileReader fr = new FileReader("J:\\BC3_IMT_Training\\Research Paper Terms.txt");
		BufferedReader fbr = new BufferedReader(fr);
		String str= fbr.readLine();
		while(str!=null){
			al.add(str);
			str=fbr.readLine();
		}
		return al;
		
	}
}
